package com.softstao.guoyu.model;

import com.kymjs.rxvolley.rx.Result;

import org.json.JSONArray;
import org.json.JSONObject;

/**
 * Created by zhanghongbo on 16-1-13.
 */
public class ResponseEntity {

    public enum ERROR
    {
        SUCCESS(0),
        FAILED(1);
        public final int fId;
        ERROR(int value) {
            this.fId = value;
        }

        public static ERROR integerToEnum(int integer) {
            switch (integer)
            {
                case 0:
                    return SUCCESS;
            }

            return FAILED;
        }
    }
    private Object data;
    private String errMsg;
    private int errCode;
    private String url;
    private Object pageInfo;
    public void fromJson(JSONObject jsonObject)
    {
        this.errCode = jsonObject.optInt("errCode");
        this.errMsg = jsonObject.optString("errMsg");
        this.data = jsonObject.opt("data");
        this.pageInfo = jsonObject.opt("pageInfo");
    }

    public void setData(Object data) {
        this.data = data;
    }


    public Object getData() {
        if(data instanceof String && data.equals("")) {
            return new JSONArray();
        }
        return data;
    }

    public String getDataString(){
        if(data instanceof String && data.equals("")) {
            return "";
        }
        else{
            return data.toString().replace("\"\"","null");
        }
    }

    public Object getData(Result result){
        if(data instanceof String && data.equals(""))
        {
            return new JSONArray();
        }
        return data;
    }

    public String getErrMsg() {
        return errMsg;
    }

    public void setErrMsg(String errMsg) {
        this.errMsg = errMsg;
    }

    public int getErrCode() {
        return errCode;
    }

    public void setErrCode(int errCode) {
        this.errCode = errCode;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public Object getPageInfo() {
        return pageInfo;
    }

    public void setPageInfo(Object pageInfo) {
        this.pageInfo = pageInfo;
    }
}
